package com.lu.component.http.proxy.config;

import com.lu.component.rpc.model.domain.response.RpcResponse;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * rpc应用上下文
 *
 * @author: zhanglu
 * @date: 2023/7/7 12:16
 * @modify: 修改人信息, 修改内容 2023/7/7 12:16
 */
public class RpcApplicationContext {

    //连接、读取超时时间
    public static final Long TIMEOUT = 10000L;

    //接口响应结果
    public static final ThreadLocal<RpcResponse> RPC_RESPONSE_THREAD_LOCAL = new InheritableThreadLocal<>();

    //代理对象
    public static final Map<Class<?>, Object> RPC_CLIENT_PROXY_CLASS_BEAN_MAP = new ConcurrentHashMap<>();

    //客户端-可选项配置
    public static final RpcClientProperties RPC_CLIENT_PROPERTIES = new RpcClientProperties();

    /**
     * 获取单例
     * @param t     class
     * @param <T>   object
     * @return
     */
    public static <T> T getBean(Class<T> t){
        return (T) RPC_CLIENT_PROXY_CLASS_BEAN_MAP.get(t);
    }

}
